package com.ttbj.timer.po;

import java.io.Serializable;
import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

public class AchievedOrder  implements Delayed, Serializable {

	 
	private static final long serialVersionUID = -6953348166171383074L;
 
	/**
	 * 订单id
	 */
	private Long orderId;
	/**
	 * 起始时间
	 */
	private long startTime;
	

	public AchievedOrder() {
	}

	public AchievedOrder(long orderId, long startTime) {
		super();
		this.orderId = orderId;
		this.startTime = startTime+System.currentTimeMillis();
	}

 
	public Long getOrderId() {
		return orderId;
	}

	public void setOrderId(Long orderId) {
		this.orderId = orderId;
	}

	public long getStartTime() {
		return startTime;
	}

	public void setStartTime(long startTime) {
		this.startTime = startTime;
	}

	@Override
	public int compareTo(Delayed o) {
		if (o == this)
			return 0;
		if (o instanceof AchievedOrder) {
			AchievedOrder order = (AchievedOrder) o;
			 if(this.startTime > order.getStartTime()){
				 return 1;
			 }else if(this.startTime==order.getStartTime()){
				 return 0;
			 }else {
				 return -1;
			 }
		}
		return 0;
	}

	@Override
	public long getDelay(TimeUnit unit) {
		return unit.convert(startTime - System.currentTimeMillis(), TimeUnit.MILLISECONDS);
	}

	@Override
	public int hashCode() {
		final int primeValue = 31;
		int result = 1;
		result = primeValue * result + (int) (orderId ^ (orderId >>> 32));
		return primeValue * result + (int) (startTime ^ (startTime >>> 32));
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null)
			return false;
		if (this == obj)
			return true;
		if (getClass() != obj.getClass())
			return false;
		AchievedOrder order = (AchievedOrder) obj;
		if (orderId != order.getOrderId())
			return false;
		if (startTime != order.getStartTime())
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "AchievedOrder [orderId=" + orderId + ", startTime=" + startTime + "]";
	}
	
	
	
}
